package pms.sg.service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.jdbc.support.rowset.SqlRowSet;

import pms.common.value.ProjectValue;
import pms.common.value.sgNewValue;
import pms.common.dao.NewSGDao;
import pms.common.dao.ListSGDao;
import pms.common.dao.ProjectDao;



public  class NewSGServiceImpl implements NewSGService{
	private NewSGDao newSGDao;
	private ListSGDao listSGDao;
	private ProjectDao projectDao;
	
	public ProjectDao getProjectDao() {
		return projectDao;
	}
	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}
	public ListSGDao getListSGDao() {
		return listSGDao;
	}
	public void setListSGDao(ListSGDao listSGDao) {
		this.listSGDao = listSGDao;
	}
	public NewSGDao getNewSGDao() {
		return newSGDao;
	}
	public void setNewSGDao(NewSGDao newSGDao) {
		this.newSGDao = newSGDao;
	}
	//プロジェクト
	public List<ProjectValue> getProjectList(){
		return projectDao.getProjectList();
	}
	// 所属テーマ
	@SuppressWarnings("unchecked")
	public List<HashMap> getFunctionArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return listSGDao.getFunctionArray();
    }
	//テスト段階
	@SuppressWarnings("unchecked")
	public List<HashMap> getTestlvlArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("test_level");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
           	l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
           	l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("TEST_LVL:" + l_array);
        return l_array;
    }
	// 検出側
	@SuppressWarnings("unchecked")
	public List<HashMap> getTestPartArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("test_part");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
           	l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
           	l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("TEST_PART:" + l_array);
        return l_array;
    }
	// 検出者
	@SuppressWarnings("unchecked")
	public List<HashMap> getUserArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
		List<HashMap> l_array = new ArrayList();
		l_array = listSGDao.getUserData();
		return l_array;
	}
	// ステータス
	@SuppressWarnings("unchecked")
	public List<HashMap> getStatusArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("bug_status");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
           	l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
           	l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("ZH_STATUS:" + l_array);
        return l_array;
    }
	
	// 障害要因
	@SuppressWarnings("unchecked")
	public List<HashMap> getReasonArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("bug_reason");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
           	l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
           	l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("ZH_REASON:" + l_array);
        return l_array;
    }
	public void doInsert(sgNewValue sgnew) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException, IOException{
		newSGDao.doInsert(sgnew);
	}
}
